

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="zh" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Trial &mdash; Optuna 1.4.0 文档</title>
  

  
  
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
  
  
  

  
  <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/custom.css" type="text/css" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="Visualization" href="visualization.html" />
    <link rel="prev" title="Study" href="study.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home"> Optuna
          

          
          </a>

          
            
            
              <div class="version">
                1.4.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">目录</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../installation.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">教程</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">API Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="core.html">Core</a></li>
<li class="toctree-l2"><a class="reference internal" href="cli.html">Command Line Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="distributions.html">Distributions</a></li>
<li class="toctree-l2"><a class="reference internal" href="exceptions.html">Exceptions</a></li>
<li class="toctree-l2"><a class="reference internal" href="importance.html">Hyperparameter Importance</a></li>
<li class="toctree-l2"><a class="reference internal" href="integration.html">Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="logging.html">Logging</a></li>
<li class="toctree-l2"><a class="reference internal" href="multi_objective/index.html">Multi-objective</a></li>
<li class="toctree-l2"><a class="reference internal" href="pruners.html">Pruners</a></li>
<li class="toctree-l2"><a class="reference internal" href="samplers.html">Samplers</a></li>
<li class="toctree-l2"><a class="reference internal" href="storages.html">Storages</a></li>
<li class="toctree-l2"><a class="reference internal" href="structs.html">Structs</a></li>
<li class="toctree-l2"><a class="reference internal" href="study.html">Study</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Trial</a></li>
<li class="toctree-l2"><a class="reference internal" href="visualization.html">Visualization</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../faq.html">常见问题</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Optuna</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="index.html">API Reference</a> &raquo;</li>
        
      <li>Trial</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/reference/trial.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <span class="target" id="module-optuna.trial"></span><div class="section" id="trial">
<h1>Trial<a class="headerlink" href="#trial" title="永久链接至标题">¶</a></h1>
<dl class="py class">
<dt id="optuna.trial.Trial">
<em class="property">class </em><code class="sig-prename descclassname">optuna.trial.</code><code class="sig-name descname">Trial</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">study</span></em>, <em class="sig-param"><span class="n">trial_id</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial" title="永久链接至目标">¶</a></dt>
<dd><p>一个 Trial 是一个评估目标函数的过程。</p>
<p>该对象被传递给目标函数，并提供接口以获取 parameter suggestion, 管理 trial 状态以及设置/获取 trial 的用户定义属性。</p>
<p>请注意，我们不建议直接使用此构造函数。 该对象被无缝实例化，并传递给 <a class="reference internal" href="study.html#optuna.study.Study.optimize" title="optuna.study.Study.optimize"><code class="xref py py-func docutils literal notranslate"><span class="pre">optuna.study.Study.optimize()</span></code></a> 方法后面的目标函数； 因此，库用户并不关心该对象的实例化。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>study</strong> -- A <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> object.</p></li>
<li><p><strong>trial_id</strong> -- A trial ID that is automatically generated.</p></li>
</ul>
</dd>
</dl>
<dl class="py method">
<dt id="optuna.trial.Trial.datetime_start">
<em class="property">property </em><code class="sig-name descname">datetime_start</code><a class="headerlink" href="#optuna.trial.Trial.datetime_start" title="永久链接至目标">¶</a></dt>
<dd><p>返回开始日期时间</p>
<dl class="field-list simple">
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>Datetime where the <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> started.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.distributions">
<em class="property">property </em><code class="sig-name descname">distributions</code><a class="headerlink" href="#optuna.trial.Trial.distributions" title="永久链接至目标">¶</a></dt>
<dd><p>返回待优化参数的分布。</p>
<dl class="field-list simple">
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>一个包含所有分布的字典。</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.number">
<em class="property">property </em><code class="sig-name descname">number</code><a class="headerlink" href="#optuna.trial.Trial.number" title="永久链接至目标">¶</a></dt>
<dd><p>返回 trial 的连续且唯一的编号。</p>
<dl class="field-list simple">
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>A trial number.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.params">
<em class="property">property </em><code class="sig-name descname">params</code><a class="headerlink" href="#optuna.trial.Trial.params" title="永久链接至目标">¶</a></dt>
<dd><p>Return parameters to be optimized.</p>
<dl class="field-list simple">
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>一个包含所有参数的字典.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.report">
<code class="sig-name descname">report</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">value</span></em>, <em class="sig-param"><span class="n">step</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial.report"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial.report" title="永久链接至目标">¶</a></dt>
<dd><p>报告给定的步骤下目标函数值。</p>
<p>Pruner 使用报告的值来确定是否应对该 trial 剪枝。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<p>参见 <a class="reference internal" href="pruners.html#optuna.pruners.BasePruner" title="optuna.pruners.BasePruner"><code class="xref py py-class docutils literal notranslate"><span class="pre">BasePruner</span></code></a>.</p>
</div>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>报告值在内部被 <code class="docutils literal notranslate"><span class="pre">float()</span></code> 函数转换成 <code class="docutils literal notranslate"><span class="pre">float</span></code> 类型。因此，它接受所有类似float的类型（例如 <code class="docutils literal notranslate"><span class="pre">numpy.float32''</span> <span class="pre">）。</span> <span class="pre">如果转换失败，则会引发</span> <span class="pre">``TypeError</span></code>.</p>
</div>
<p class="rubric">示例</p>
<p>报告 <cite>SGDClassifier &lt;https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDClassifier.html&gt;</cite> 在训练中的中间值。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">load_iris</span>
<span class="kn">from</span> <span class="nn">sklearn.linear_model</span> <span class="kn">import</span> <span class="n">SGDClassifier</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>

<span class="kn">import</span> <span class="nn">optuna</span>

<span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">load_iris</span><span class="p">(</span><span class="n">return_X_y</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">clf</span> <span class="o">=</span> <span class="n">SGDClassifier</span><span class="p">(</span><span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">100</span><span class="p">):</span>
        <span class="n">clf</span><span class="o">.</span><span class="n">partial_fit</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">y</span><span class="p">))</span>
        <span class="n">intermediate_value</span> <span class="o">=</span> <span class="n">clf</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">)</span>
        <span class="n">trial</span><span class="o">.</span><span class="n">report</span><span class="p">(</span><span class="n">intermediate_value</span><span class="p">,</span> <span class="n">step</span><span class="o">=</span><span class="n">step</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">trial</span><span class="o">.</span><span class="n">should_prune</span><span class="p">():</span>
            <span class="k">raise</span> <span class="n">optuna</span><span class="o">.</span><span class="n">TrialPruned</span><span class="p">()</span>

    <span class="k">return</span> <span class="n">clf</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">)</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">direction</span><span class="o">=</span><span class="s1">&#39;maximize&#39;</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>value</strong> -- 从目标函数返回的值。</p></li>
<li><p><strong>step</strong> -- Trial 步骤（例如，神经网络训练的 epoch）。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.set_user_attr">
<code class="sig-name descname">set_user_attr</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">key</span></em>, <em class="sig-param"><span class="n">value</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial.set_user_attr"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial.set_user_attr" title="永久链接至目标">¶</a></dt>
<dd><p>将用户属性设置到 trial中。</p>
<p>可以通过 <a class="reference internal" href="#optuna.trial.Trial.user_attrs" title="optuna.trial.Trial.user_attrs"><code class="xref py py-func docutils literal notranslate"><span class="pre">optuna.trial.Trial.user_attrs()</span></code></a> 访问试 trial 中的用户属性。</p>
<p class="rubric">示例</p>
<p>保存神经网络训练的固定超参数。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">load_iris</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>
<span class="kn">from</span> <span class="nn">sklearn.neural_network</span> <span class="kn">import</span> <span class="n">MLPClassifier</span>

<span class="kn">import</span> <span class="nn">optuna</span>

<span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">load_iris</span><span class="p">(</span><span class="n">return_X_y</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">trial</span><span class="o">.</span><span class="n">set_user_attr</span><span class="p">(</span><span class="s1">&#39;BATCHSIZE&#39;</span><span class="p">,</span> <span class="mi">128</span><span class="p">)</span>
    <span class="n">momentum</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;momentum&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="n">clf</span> <span class="o">=</span> <span class="n">MLPClassifier</span><span class="p">(</span><span class="n">hidden_layer_sizes</span><span class="o">=</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">50</span><span class="p">),</span>
                        <span class="n">batch_size</span><span class="o">=</span><span class="n">trial</span><span class="o">.</span><span class="n">user_attrs</span><span class="p">[</span><span class="s1">&#39;BATCHSIZE&#39;</span><span class="p">],</span>
                        <span class="n">momentum</span><span class="o">=</span><span class="n">momentum</span><span class="p">,</span> <span class="n">solver</span><span class="o">=</span><span class="s1">&#39;sgd&#39;</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">clf</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">clf</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">)</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">direction</span><span class="o">=</span><span class="s1">&#39;maximize&#39;</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
<span class="k">assert</span> <span class="s1">&#39;BATCHSIZE&#39;</span> <span class="ow">in</span> <span class="n">study</span><span class="o">.</span><span class="n">best_trial</span><span class="o">.</span><span class="n">user_attrs</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="k">assert</span> <span class="n">study</span><span class="o">.</span><span class="n">best_trial</span><span class="o">.</span><span class="n">user_attrs</span><span class="p">[</span><span class="s1">&#39;BATCHSIZE&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">128</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>key</strong> -- A key string of the attribute.</p></li>
<li><p><strong>value</strong> -- 属性的值。 该值应为JSON可序列化的。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.should_prune">
<code class="sig-name descname">should_prune</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.8)">bool</a><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial.should_prune"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial.should_prune" title="永久链接至目标">¶</a></dt>
<dd><p>建议是否应修剪该 trial.</p>
<p>该 suggestion 是基于先前报告的值并通过与试验相关的 pruning 算法提出的。 可以在构造一个 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 时指定该算法。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>如果未报告任何值，则该算法无法提出有意义的 suggestion。 同样，如果使用完全相同的一组报告值多次调用此方法，则 suggestion 也将相同。</p>
</div>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<p>请参考 <a class="reference internal" href="#optuna.trial.Trial.report" title="optuna.trial.Trial.report"><code class="xref py py-func docutils literal notranslate"><span class="pre">optuna.trial.Trial.report()</span></code></a> 的示例代码。</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>一个布尔值。如果为 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a>, 则应根据配置的 pruning 算法对 trial 进行修剪。否则， trial 应继续进行。</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.suggest_categorical">
<code class="sig-name descname">suggest_categorical</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="n">choices</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial.suggest_categorical"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial.suggest_categorical" title="永久链接至目标">¶</a></dt>
<dd><p>为分类参数提供一个 suggestion.</p>
<p>这个值是用 <code class="docutils literal notranslate"><span class="pre">choices</span></code> 进行采样的。</p>
<p class="rubric">示例</p>
<p>为 <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html">SVC</a> 提供一个 suggestion.</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">load_iris</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>
<span class="kn">from</span> <span class="nn">sklearn.svm</span> <span class="kn">import</span> <span class="n">SVC</span>

<span class="kn">import</span> <span class="nn">optuna</span>

<span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">load_iris</span><span class="p">(</span><span class="n">return_X_y</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">kernel</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_categorical</span><span class="p">(</span><span class="s1">&#39;kernel&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;linear&#39;</span><span class="p">,</span> <span class="s1">&#39;poly&#39;</span><span class="p">,</span> <span class="s1">&#39;rbf&#39;</span><span class="p">])</span>
    <span class="n">clf</span> <span class="o">=</span> <span class="n">SVC</span><span class="p">(</span><span class="n">kernel</span><span class="o">=</span><span class="n">kernel</span><span class="p">,</span> <span class="n">gamma</span><span class="o">=</span><span class="s1">&#39;scale&#39;</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">clf</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">clf</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">)</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">direction</span><span class="o">=</span><span class="s1">&#39;maximize&#39;</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> -- A parameter name.</p></li>
<li><p><strong>choices</strong> -- Parameter value candidates.</p></li>
</ul>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<p><a class="reference internal" href="distributions.html#optuna.distributions.CategoricalDistribution" title="optuna.distributions.CategoricalDistribution"><code class="xref py py-class docutils literal notranslate"><span class="pre">CategoricalDistribution</span></code></a>.</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>A suggested value.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.suggest_discrete_uniform">
<code class="sig-name descname">suggest_discrete_uniform</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="n">low</span></em>, <em class="sig-param"><span class="n">high</span></em>, <em class="sig-param"><span class="n">q</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial.suggest_discrete_uniform"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial.suggest_discrete_uniform" title="永久链接至目标">¶</a></dt>
<dd><p>提供离散参数的 suggestion.</p>
<p>该值是从 <span class="math notranslate nohighlight">\([\mathsf{low}, \mathsf{high}]\)</span> 中采样的，并且其离散化的步数是:math:<cite>q</cite>. 更具体地说，该方法返回 <span class="math notranslate nohighlight">\(\mathsf{low}, \mathsf{low} + q, \mathsf{low} + 2 q, \dots, \mathsf{low} + k q \le \mathsf{high}\)</span> 序列中的一个值，其中:math:<cite>k</cite> 代表一个整数。注意，如果 <span class="math notranslate nohighlight">\(q\)</span> 不是整数的话，<span class="math notranslate nohighlight">\(high\)</span>  可能因为舍入误差而不同。请通过检查 warning 信息来找到改变的值。</p>
<p class="rubric">示例</p>
<p>为 拟合 <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingClassifier.html">GradientBoostingClassifier</a> 的各个 learner 所需的样本个数提供一个 suggestion.</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">load_iris</span>
<span class="kn">from</span> <span class="nn">sklearn.ensemble</span> <span class="kn">import</span> <span class="n">GradientBoostingClassifier</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>

<span class="kn">import</span> <span class="nn">optuna</span>

<span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">load_iris</span><span class="p">(</span><span class="n">return_X_y</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">subsample</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_discrete_uniform</span><span class="p">(</span><span class="s1">&#39;subsample&#39;</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">)</span>
    <span class="n">clf</span> <span class="o">=</span> <span class="n">GradientBoostingClassifier</span><span class="p">(</span><span class="n">subsample</span><span class="o">=</span><span class="n">subsample</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">clf</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">clf</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">)</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">direction</span><span class="o">=</span><span class="s1">&#39;maximize&#39;</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> -- A parameter name.</p></li>
<li><p><strong>low</strong> -- Suggestion 值范围的下限。 <code class="docutils literal notranslate"><span class="pre">low</span></code> 包含在范围内。</p></li>
<li><p><strong>high</strong> -- Suggestion 值范围的上限。 <code class="docutils literal notranslate"><span class="pre">high</span></code> 包含在范围内。</p></li>
<li><p><strong>q</strong> -- 一个离散化步骤</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>A suggested float value.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.suggest_float">
<code class="sig-name descname">suggest_float</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span></em>, <em class="sig-param"><span class="n">low</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(在 Python v3.8)">float</a></span></em>, <em class="sig-param"><span class="n">high</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(在 Python v3.8)">float</a></span></em>, <em class="sig-param"><span class="o">*</span></em>, <em class="sig-param"><span class="n">step</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(在 Python v3.8)">float</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">log</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.8)">bool</a></span> <span class="o">=</span> <span class="default_value">False</span></em><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(在 Python v3.8)">float</a><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial.suggest_float"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial.suggest_float" title="永久链接至目标">¶</a></dt>
<dd><p>提供一个 浮点数的 suggestion.</p>
<p>注意，这事一个用于 <a class="reference internal" href="#optuna.trial.Trial.suggest_uniform" title="optuna.trial.Trial.suggest_uniform"><code class="xref py py-func docutils literal notranslate"><span class="pre">suggest_uniform()</span></code></a>, <a class="reference internal" href="#optuna.trial.Trial.suggest_loguniform" title="optuna.trial.Trial.suggest_loguniform"><code class="xref py py-func docutils literal notranslate"><span class="pre">suggest_loguniform()</span></code></a> 和 <a class="reference internal" href="#optuna.trial.Trial.suggest_discrete_uniform" title="optuna.trial.Trial.suggest_discrete_uniform"><code class="xref py py-func docutils literal notranslate"><span class="pre">suggest_discrete_uniform()</span></code></a> 的 wrapper 方法。</p>
<div class="versionadded">
<p><span class="versionmodified added">1.3.0 新版功能.</span></p>
</div>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<p>参见 <a class="reference internal" href="#optuna.trial.Trial.suggest_uniform" title="optuna.trial.Trial.suggest_uniform"><code class="xref py py-func docutils literal notranslate"><span class="pre">suggest_uniform()</span></code></a>, <a class="reference internal" href="#optuna.trial.Trial.suggest_loguniform" title="optuna.trial.Trial.suggest_loguniform"><code class="xref py py-func docutils literal notranslate"><span class="pre">suggest_loguniform()</span></code></a> 和 <a class="reference internal" href="#optuna.trial.Trial.suggest_discrete_uniform" title="optuna.trial.Trial.suggest_discrete_uniform"><code class="xref py py-func docutils literal notranslate"><span class="pre">suggest_discrete_uniform()</span></code></a>.</p>
</div>
<p class="rubric">示例</p>
<p>为神经网络训练提供 momentum，learning rate 和 learning rate 的比例因子的suggestion 值。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">load_iris</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>
<span class="kn">from</span> <span class="nn">sklearn.neural_network</span> <span class="kn">import</span> <span class="n">MLPClassifier</span>

<span class="kn">import</span> <span class="nn">optuna</span>

<span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">load_iris</span><span class="p">(</span><span class="n">return_X_y</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">momentum</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_float</span><span class="p">(</span><span class="s1">&#39;momentum&#39;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="n">learning_rate_init</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_float</span><span class="p">(</span><span class="s1">&#39;learning_rate_init&#39;</span><span class="p">,</span>
                                             <span class="mf">1e-5</span><span class="p">,</span> <span class="mf">1e-3</span><span class="p">,</span> <span class="n">log</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">power_t</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_float</span><span class="p">(</span><span class="s1">&#39;power_t&#39;</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="n">step</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span>
    <span class="n">clf</span> <span class="o">=</span> <span class="n">MLPClassifier</span><span class="p">(</span><span class="n">hidden_layer_sizes</span><span class="o">=</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">50</span><span class="p">),</span> <span class="n">momentum</span><span class="o">=</span><span class="n">momentum</span><span class="p">,</span>
                        <span class="n">learning_rate_init</span><span class="o">=</span><span class="n">learning_rate_init</span><span class="p">,</span>
                        <span class="n">solver</span><span class="o">=</span><span class="s1">&#39;sgd&#39;</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">power_t</span><span class="o">=</span><span class="n">power_t</span><span class="p">)</span>
    <span class="n">clf</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">clf</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">)</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">direction</span><span class="o">=</span><span class="s1">&#39;maximize&#39;</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> -- A parameter name.</p></li>
<li><p><strong>low</strong> -- Suggestion 值范围的下限。 <code class="docutils literal notranslate"><span class="pre">low</span></code> 包含在范围内。</p></li>
<li><p><strong>high</strong> -- Suggestion 值范围的上限。 <code class="docutils literal notranslate"><span class="pre">high</span></code> 不包含在范围内。</p></li>
<li><p><strong>step</strong> -- 一个离散化步骤 .. note::  <code class="docutils literal notranslate"><span class="pre">step</span></code> 和 <code class="docutils literal notranslate"><span class="pre">log</span></code> 参数不能同时使用。要把 <code class="docutils literal notranslate"><span class="pre">step</span></code> 设置成浮点数的话，请先把 <code class="docutils literal notranslate"><span class="pre">log</span></code> 参数设置成 <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p></li>
<li><p><strong>log</strong> -- 是否从对数域采样值的设置选项。如果 <code class="docutils literal notranslate"><span class="pre">log</span></code> 是 true，则从对数域中的范围采样该值，否则将从线性域中的范围采样。参见 <a class="reference internal" href="#optuna.trial.Trial.suggest_uniform" title="optuna.trial.Trial.suggest_uniform"><code class="xref py py-func docutils literal notranslate"><span class="pre">suggest_uniform()</span></code></a> 和 <a class="reference internal" href="#optuna.trial.Trial.suggest_loguniform" title="optuna.trial.Trial.suggest_loguniform"><code class="xref py py-func docutils literal notranslate"><span class="pre">suggest_loguniform()</span></code></a>... note::     <code class="docutils literal notranslate"><span class="pre">step</span></code> 和 <code class="docutils literal notranslate"><span class="pre">log</span></code> 参数不能同时使用。要把 <code class="docutils literal notranslate"><span class="pre">step</span></code> 设置成浮点数的话，请先把 <code class="docutils literal notranslate"><span class="pre">log</span></code> 参数设置成 <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p></li>
</ul>
</dd>
<dt class="field-even">引发</dt>
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(在 Python v3.8)"><strong>ValueError</strong></a> -- 如果 <code class="docutils literal notranslate"><span class="pre">step</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">None</span></code> 并且制定了 <code class="docutils literal notranslate"><span class="pre">log</span> <span class="pre">=</span> <span class="pre">True</span></code>.</p>
</dd>
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>A suggested float value.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.suggest_int">
<code class="sig-name descname">suggest_int</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span></em>, <em class="sig-param"><span class="n">low</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a></span></em>, <em class="sig-param"><span class="n">high</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a></span></em>, <em class="sig-param"><span class="n">step</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a></span> <span class="o">=</span> <span class="default_value">1</span></em>, <em class="sig-param"><span class="n">log</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.8)">bool</a></span> <span class="o">=</span> <span class="default_value">False</span></em><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial.suggest_int"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial.suggest_int" title="永久链接至目标">¶</a></dt>
<dd><p>提供一个整数 suggestion.</p>
<p>该值是从 <span class="math notranslate nohighlight">\([\mathsf{low}, \mathsf{high}]\)</span> 中采样的。</p>
<p class="rubric">示例</p>
<p>为 <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html">RandomForestClassifier</a> 提供一个关于树个数的 suggestion.</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">load_iris</span>
<span class="kn">from</span> <span class="nn">sklearn.ensemble</span> <span class="kn">import</span> <span class="n">RandomForestClassifier</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>

<span class="kn">import</span> <span class="nn">optuna</span>

<span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">load_iris</span><span class="p">(</span><span class="n">return_X_y</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">n_estimators</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_int</span><span class="p">(</span><span class="s1">&#39;n_estimators&#39;</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="mi">400</span><span class="p">)</span>
    <span class="n">clf</span> <span class="o">=</span> <span class="n">RandomForestClassifier</span><span class="p">(</span><span class="n">n_estimators</span><span class="o">=</span><span class="n">n_estimators</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">clf</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">clf</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">)</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">direction</span><span class="o">=</span><span class="s1">&#39;maximize&#39;</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> -- A parameter name.</p></li>
<li><p><strong>low</strong> -- Suggestion 值范围的下限。 <code class="docutils literal notranslate"><span class="pre">low</span></code> 包含在范围内。</p></li>
<li><p><strong>high</strong> -- Suggestion 值范围的上限。 <code class="docutils literal notranslate"><span class="pre">high</span></code> 包含在范围内。</p></li>
<li><p><strong>step</strong> -- 一个离散化步骤。  .. note::     注意， <span class="math notranslate nohighlight">\(\mathsf{high}\)</span> 会被改变，如果该范围无法被 <span class="math notranslate nohighlight">\(\mathsf{step}\)</span> 整除的话。 请通过检查 warning 信息来找出改变了的值。 .. note::     该方法返回序列     <span class="math notranslate nohighlight">\(\mathsf{low}, \mathsf{low} + \mathsf{step}, \mathsf{low} + 2 *     \mathsf{step}, \dots, \mathsf{low} + k * \mathsf{step} \le     \mathsf{high}\)</span> 中的一个值，其中 <span class="math notranslate nohighlight">\(k\)</span> 代表一个整数.  .. note::     参数 <code class="docutils literal notranslate"><span class="pre">step</span> <span class="pre">!=</span> <span class="pre">1</span></code> and <code class="docutils literal notranslate"><span class="pre">log</span></code> 不能同时使用。     要把 <code class="docutils literal notranslate"><span class="pre">step</span></code> 设置成 <span class="math notranslate nohighlight">\(\mathsf{step} \ge 2\)</span> 的话， 先把     <code class="docutils literal notranslate"><span class="pre">log</span></code> 设置成 <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p></li>
<li><p><strong>log</strong> -- 是否从对数域采样值的设置选项。.. note::     如果``log`` 是 true，则在一开始的时候， suggestion 值的范围会被分成宽度为 1 的网格点。然后 suggestion 值会被转化到对数域，并在该域上进行采样。这些均匀采样的值会被重新转换到原来的线性域上，并且被舍入到最近的网格点中。这就是确定采样值的过程。比如，如果 <cite>low = 2</cite> 且 <cite>high = 8</cite> 的话， suggestion 值的范围就是     <cite>[2, 3, 4, 5, 6, 7, 8]</cite> 而且较小的值有更大的概率被采样到。<code class="docutils literal notranslate"><span class="pre">step</span> <span class="pre">!=</span> <span class="pre">1</span></code> 和 <code class="docutils literal notranslate"><span class="pre">log</span></code> 参数不能同时使用要把 <code class="docutils literal notranslate"><span class="pre">log</span></code> 设置成 <code class="docutils literal notranslate"><span class="pre">True</span></code> 的话，请先把 <code class="docutils literal notranslate"><span class="pre">step</span></code> 设置成 1.</p></li>
</ul>
</dd>
<dt class="field-even">引发</dt>
<dd class="field-even"><p><a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(在 Python v3.8)"><strong>ValueError</strong></a> -- 如果 <code class="docutils literal notranslate"><span class="pre">step</span> <span class="pre">!=</span> <span class="pre">1</span></code> and <code class="docutils literal notranslate"><span class="pre">log</span> <span class="pre">=</span> <span class="pre">True</span></code> 被确定了</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.suggest_loguniform">
<code class="sig-name descname">suggest_loguniform</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="n">low</span></em>, <em class="sig-param"><span class="n">high</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial.suggest_loguniform"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial.suggest_loguniform" title="永久链接至目标">¶</a></dt>
<dd><p>从连续参数值中提供 suggestion.</p>
<p>该值是从对数域的 <span class="math notranslate nohighlight">\([\mathsf{low}, \mathsf{high}]\)</span> 中采样的。当 mathsf{low} = mathsf{high}` 时，返回结果是 <span class="math notranslate nohighlight">\(\mathsf{low}\)</span>.</p>
<p class="rubric">示例</p>
<p>为 <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html">SVC</a>. 的罚参数 <code class="docutils literal notranslate"><span class="pre">C</span></code> 提供一个 suggestion 值。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">load_iris</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>
<span class="kn">from</span> <span class="nn">sklearn.svm</span> <span class="kn">import</span> <span class="n">SVC</span>

<span class="kn">import</span> <span class="nn">optuna</span>

<span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">load_iris</span><span class="p">(</span><span class="n">return_X_y</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">c</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_loguniform</span><span class="p">(</span><span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="mf">1e-5</span><span class="p">,</span> <span class="mf">1e2</span><span class="p">)</span>
    <span class="n">clf</span> <span class="o">=</span> <span class="n">SVC</span><span class="p">(</span><span class="n">C</span><span class="o">=</span><span class="n">c</span><span class="p">,</span> <span class="n">gamma</span><span class="o">=</span><span class="s1">&#39;scale&#39;</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">clf</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">clf</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">)</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">direction</span><span class="o">=</span><span class="s1">&#39;maximize&#39;</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> -- A parameter name.</p></li>
<li><p><strong>low</strong> -- Suggestion 值范围的下限。 <code class="docutils literal notranslate"><span class="pre">low</span></code> 包含在范围内。</p></li>
<li><p><strong>high</strong> -- Suggestion 值范围的上限。 <code class="docutils literal notranslate"><span class="pre">high</span></code> 不包含在范围内。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>A suggested float value.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.suggest_uniform">
<code class="sig-name descname">suggest_uniform</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">name</span></em>, <em class="sig-param"><span class="n">low</span></em>, <em class="sig-param"><span class="n">high</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/trial/_trial.html#Trial.suggest_uniform"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.Trial.suggest_uniform" title="永久链接至目标">¶</a></dt>
<dd><p>从连续参数值中提供 suggestion.</p>
<p>该值是从线性域的 <span class="math notranslate nohighlight">\([\mathsf{low}, \mathsf{high}]\)</span> 中采样的。当 mathsf{low} = mathsf{high}` 时，返回结果是 <span class="math notranslate nohighlight">\(\mathsf{low}\)</span>.</p>
<p class="rubric">示例</p>
<p>为神经网络训练提出 momentum 的suggestion 值。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">load_iris</span>
<span class="kn">from</span> <span class="nn">sklearn.model_selection</span> <span class="kn">import</span> <span class="n">train_test_split</span>
<span class="kn">from</span> <span class="nn">sklearn.neural_network</span> <span class="kn">import</span> <span class="n">MLPClassifier</span>

<span class="kn">import</span> <span class="nn">optuna</span>

<span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">load_iris</span><span class="p">(</span><span class="n">return_X_y</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">train_test_split</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">momentum</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;momentum&#39;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="n">clf</span> <span class="o">=</span> <span class="n">MLPClassifier</span><span class="p">(</span><span class="n">hidden_layer_sizes</span><span class="o">=</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">50</span><span class="p">),</span> <span class="n">momentum</span><span class="o">=</span><span class="n">momentum</span><span class="p">,</span>
                        <span class="n">solver</span><span class="o">=</span><span class="s1">&#39;sgd&#39;</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
    <span class="n">clf</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">clf</span><span class="o">.</span><span class="n">score</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">)</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">direction</span><span class="o">=</span><span class="s1">&#39;maximize&#39;</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>name</strong> -- A parameter name.</p></li>
<li><p><strong>low</strong> -- Suggestion 值范围的下限。 <code class="docutils literal notranslate"><span class="pre">low</span></code> 包含在范围内。</p></li>
<li><p><strong>high</strong> -- Suggestion 值范围的上限。 <code class="docutils literal notranslate"><span class="pre">high</span></code> 不包含在范围内。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>A suggested float value.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.Trial.user_attrs">
<em class="property">property </em><code class="sig-name descname">user_attrs</code><a class="headerlink" href="#optuna.trial.Trial.user_attrs" title="永久链接至目标">¶</a></dt>
<dd><p>返回用户属性</p>
<dl class="field-list simple">
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>包含所有用户属性的字典。</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt id="optuna.trial.FixedTrial">
<em class="property">class </em><code class="sig-prename descclassname">optuna.trial.</code><code class="sig-name descname">FixedTrial</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">params</span></em>, <em class="sig-param"><span class="n">number</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/trial/_fixed.html#FixedTrial"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.FixedTrial" title="永久链接至目标">¶</a></dt>
<dd><p>一个始终为每个参数提供固定 suggestion 值的 trial 类。</p>
<p>该对象和 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 有着一样的方法。它提供预定义的参数值 suggestion. 这些参数值可以通过构造 <a class="reference internal" href="#optuna.trial.FixedTrial" title="optuna.trial.FixedTrial"><code class="xref py py-class docutils literal notranslate"><span class="pre">FixedTrial</span></code></a> 来决定。和 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 不同，<a class="reference internal" href="#optuna.trial.FixedTrial" title="optuna.trial.FixedTrial"><code class="xref py py-class docutils literal notranslate"><span class="pre">FixedTrial</span></code></a> 并不依赖 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a>, 这对于部署优化过程很有用。</p>
<p class="rubric">示例</p>
<p>根据用户给定的参数值对一个目标函数求解。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_categorical</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">x</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">y</span>

<span class="k">assert</span> <span class="n">objective</span><span class="p">(</span><span class="n">optuna</span><span class="o">.</span><span class="n">trial</span><span class="o">.</span><span class="n">FixedTrial</span><span class="p">({</span><span class="s1">&#39;x&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">}))</span> <span class="o">==</span> <span class="mi">1</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>关于方法和属性的细节请参考 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>.</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>params</strong> -- 一个包含所有参数的字典.</p></li>
<li><p><strong>number</strong> -- Trial 编号，默认是 <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.trial.FrozenTrial">
<em class="property">class </em><code class="sig-prename descclassname">optuna.trial.</code><code class="sig-name descname">FrozenTrial</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">number</span></em>, <em class="sig-param"><span class="n">state</span></em>, <em class="sig-param"><span class="n">value</span></em>, <em class="sig-param"><span class="n">datetime_start</span></em>, <em class="sig-param"><span class="n">datetime_complete</span></em>, <em class="sig-param"><span class="n">params</span></em>, <em class="sig-param"><span class="n">distributions</span></em>, <em class="sig-param"><span class="n">user_attrs</span></em>, <em class="sig-param"><span class="n">system_attrs</span></em>, <em class="sig-param"><span class="n">intermediate_values</span></em>, <em class="sig-param"><span class="n">trial_id</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/trial/_frozen.html#FrozenTrial"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.FrozenTrial" title="永久链接至目标">¶</a></dt>
<dd><p>一个 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 的状态和结果。</p>
<dl class="py attribute">
<dt id="optuna.trial.FrozenTrial.number">
<code class="sig-name descname">number</code><a class="headerlink" href="#optuna.trial.FrozenTrial.number" title="永久链接至目标">¶</a></dt>
<dd><p>每个 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 中 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 的连续且唯一的编号。注意这是从 0 开始计数的。</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.FrozenTrial.state">
<code class="sig-name descname">state</code><a class="headerlink" href="#optuna.trial.FrozenTrial.state" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="#optuna.trial.TrialState" title="optuna.trial.TrialState"><code class="xref py py-class docutils literal notranslate"><span class="pre">TrialState</span></code></a> of the <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>.</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.FrozenTrial.value">
<code class="sig-name descname">value</code><a class="headerlink" href="#optuna.trial.FrozenTrial.value" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 的目标函数值。</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.FrozenTrial.datetime_start">
<code class="sig-name descname">datetime_start</code><a class="headerlink" href="#optuna.trial.FrozenTrial.datetime_start" title="永久链接至目标">¶</a></dt>
<dd><p>Datetime where the <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> started.</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.FrozenTrial.datetime_complete">
<code class="sig-name descname">datetime_complete</code><a class="headerlink" href="#optuna.trial.FrozenTrial.datetime_complete" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 的完成时间。</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.FrozenTrial.params">
<code class="sig-name descname">params</code><a class="headerlink" href="#optuna.trial.FrozenTrial.params" title="永久链接至目标">¶</a></dt>
<dd><p>包含参数 suggestion 值的字典。</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.FrozenTrial.user_attrs">
<code class="sig-name descname">user_attrs</code><a class="headerlink" href="#optuna.trial.FrozenTrial.user_attrs" title="永久链接至目标">¶</a></dt>
<dd><p>通过 <a class="reference internal" href="#optuna.trial.Trial.set_user_attr" title="optuna.trial.Trial.set_user_attr"><code class="xref py py-func docutils literal notranslate"><span class="pre">optuna.trial.Trial.set_user_attr()</span></code></a> 设置的、包含了 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 属性的字典。</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.FrozenTrial.intermediate_values">
<code class="sig-name descname">intermediate_values</code><a class="headerlink" href="#optuna.trial.FrozenTrial.intermediate_values" title="永久链接至目标">¶</a></dt>
<dd><p>通过 <a class="reference internal" href="#optuna.trial.Trial.report" title="optuna.trial.Trial.report"><code class="xref py py-func docutils literal notranslate"><span class="pre">optuna.trial.Trial.report()</span></code></a> 来设定的 中间目标函数值。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.FrozenTrial.distributions">
<em class="property">property </em><code class="sig-name descname">distributions</code><a class="headerlink" href="#optuna.trial.FrozenTrial.distributions" title="永久链接至目标">¶</a></dt>
<dd><p>包含了 <a class="reference internal" href="#optuna.trial.FrozenTrial.params" title="optuna.trial.FrozenTrial.params"><code class="xref py py-attr docutils literal notranslate"><span class="pre">params</span></code></a> 分布的字典。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.trial.FrozenTrial.duration">
<em class="property">property </em><code class="sig-name descname">duration</code><a class="headerlink" href="#optuna.trial.FrozenTrial.duration" title="永久链接至目标">¶</a></dt>
<dd><p>返回完成该 trial 耗费的时间。</p>
<dl class="field-list simple">
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>持续时间。</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt id="optuna.trial.TrialState">
<em class="property">class </em><code class="sig-prename descclassname">optuna.trial.</code><code class="sig-name descname">TrialState</code><a class="reference internal" href="../_modules/optuna/trial/_state.html#TrialState"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.trial.TrialState" title="永久链接至目标">¶</a></dt>
<dd><p>State of a <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>.</p>
<dl class="py attribute">
<dt id="optuna.trial.TrialState.RUNNING">
<code class="sig-name descname">RUNNING</code><a class="headerlink" href="#optuna.trial.TrialState.RUNNING" title="永久链接至目标">¶</a></dt>
<dd><p>该 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>  处于运行中状态。</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.TrialState.COMPLETE">
<code class="sig-name descname">COMPLETE</code><a class="headerlink" href="#optuna.trial.TrialState.COMPLETE" title="永久链接至目标">¶</a></dt>
<dd><p>该 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 已完成，且未触发任何错误。</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.TrialState.PRUNED">
<code class="sig-name descname">PRUNED</code><a class="headerlink" href="#optuna.trial.TrialState.PRUNED" title="永久链接至目标">¶</a></dt>
<dd><p>该 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 已经被 <a class="reference internal" href="exceptions.html#optuna.exceptions.TrialPruned" title="optuna.exceptions.TrialPruned"><code class="xref py py-class docutils literal notranslate"><span class="pre">TrialPruned</span></code></a> 剪枝。</p>
</dd></dl>

<dl class="py attribute">
<dt id="optuna.trial.TrialState.FAIL">
<code class="sig-name descname">FAIL</code><a class="headerlink" href="#optuna.trial.TrialState.FAIL" title="永久链接至目标">¶</a></dt>
<dd><p>由于未捕获的错误，该 <a class="reference internal" href="#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 已经失败。</p>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="visualization.html" class="btn btn-neutral float-right" title="Visualization" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="study.html" class="btn btn-neutral float-left" title="Study" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Optuna Contributors.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
    <a href="../privacy.html">Privacy Policy</a>.
     


</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-55135190-8', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>